package com.wangp.mywrite.s_netty.nio.ch1;

import static com.wangp.mywrite.s_netty.nio.ch1.ByteBufferUtil.debugAll;

import java.nio.ByteBuffer;

/**
 * @author tooStronger
 * @date 2023/3/15
 */
public class TestByteBufferReadWrite {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        byteBuffer.put((byte) 0x61);
        debugAll(byteBuffer);

        byteBuffer.put(new byte[]{0x62,0x63,0x64});
       ByteBufferUtil.debugAll(byteBuffer);

        // 不做读模式切换，是读不到数据
//        System.out.println(byteBuffer.get());

        byteBuffer.flip();
        System.out.println(byteBuffer.get());
        debugAll(byteBuffer);

        byteBuffer.compact();
        debugAll(byteBuffer);
        byteBuffer.put(new byte[]{0x65,0x6f});
        ByteBufferUtil.debugAll(byteBuffer);
    }
}
